// LemCoop
// Copyright (C) 2013  Oliver Naumann <bldrax@gmail.com>

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include "allegro_bitmap_manager.h"

AllegroBitmapManager::AllegroBitmapManager(std::string resource_file_path) : ResourceManager(resource_file_path)
{
}

bool AllegroBitmapManager::LoadResource(std::string resource_id)
{
	std::string path;

	if (!GetResourcePathFromFile(resource_id, path))
	{
		LogManager::LogLine("Error: Could not open load resource '" + resource_id + "'.");
		return false;
	}

	// Load the bitmap
	ALLEGRO_BITMAP* allegro_bitmap = al_load_bitmap(path.c_str());

	if (allegro_bitmap == NULL)
	{
		LogManager::LogLine("Error: Could not open load resource '" + resource_id + "' because the file '" + path + "' could not be loaded.");
		return false;
	}

	m_resources.insert(std::make_pair(resource_id, allegro_bitmap));
	return true;
}

bool AllegroBitmapManager::DestroyResource(ALLEGRO_BITMAP* resource)
{
	al_destroy_bitmap(resource);
	return true;
}